package com.tanhua.server.controller;



import com.tanhua.server.service.MyCenterService;
import com.tanhua.server.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("users")
public class MyCenterController {

    @Autowired
    private MyCenterService myCenterService;

    // 查询黑名单
    @GetMapping("blacklist")
    public ResponseEntity<PageResult> queryBlackList(@RequestParam(value = "page",defaultValue = "1")Integer page,
                                                     @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        try {
            PageResult pageResult = this.myCenterService.queryBlackList(page, pageSize);
            return ResponseEntity.ok(pageResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    // 移除黑名单
    @DeleteMapping("blacklist/{uid}")
    public ResponseEntity<Void> delBlackList(@PathVariable("uid")Long userId){
        try {
            this.myCenterService.delBlackList(userId);
            return ResponseEntity.ok(null);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
